class Solution {
    public void moveZeroes(int[] nums) {
        int[] zeros = new int[nums.length];
        Arrays.fill(zeros, -1);
        int index = 0, p = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) zeros[index++] = i;
            else if (zeros[p] != -1 && zeros[p] < i) {
                nums[zeros[p++]] = nums[i];
                nums[i] = 0;
                zeros[index++] = i;
            }
        }
    }
}
